<template>
  <div class="main-content">
    <div class="order-table">
      <div class="order-card" v-for="(item,index) in order" :key="index">
        <div class="food-img">
          <img :src="item.imgUrl" alt="">
        </div>
        <div class="order-message">
          <span class="food-name">{{item.foodName}}</span>
          <span class="food-price">¥ {{item.foodPrice}}</span>
          <span class="food-count">×{{item.count}}</span>
        </div>
<div class="footer" >
  <span class="total-price">总计 ¥ {{totalPrice}}</span>
  <span class="submit-btn" @click="handleSubmit">提交订单</span>
</div>
      </div>
    </div>

  </div>
</template>

<script>
export default {
  data() {
    return {
      order: [],
      totalPrice:0
    }
  },
  methods: {
    handleSubmit(){
      this.request({
        url:'/submitOrder',
        method:'POST',
        data:{
          order:this.order,
          totalPrice:this.totalPrice,
          username:this.$store.state.username||localStorage.getItem("username")
        }
      }).then(res=>{
        console.log(res);
        alert('支付成功！')
        // 这里得用replace！因为支付完了以后是不能回退到支付页面，而应该回到点餐页面
        this.$router.replace({path:'mine'})
      })
    }
  },
  mounted() {
    this.order = this.$route.query.order
   this.totalPrice=this.$route.query.totalPrice
  }
}
</script>
  


<style lang="less" scoped>
.main-content {
  // 最小高度
  min-height: 100vh;
  background-color: rgba(238, 232, 232, 0.699);
}
.order-table {
  padding-top: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  .order-card {
    width: 400px;
    padding: 10px 40px 10px 20px ;
    display: flex;
    align-items: center;
    justify-content:space-around;
    margin-bottom: 20px;
    background-color: #fff;
    border-radius: 20px;
    .food-img {
    flex: 1;
    height: 95px;
    margin-right: 20px;
      img{
        width: 100%;
        height: 100%;
        border-radius: 10px;
        border: 1px solid #ccc;
      }
    }
    .order-message {
      flex: 3;
      height: 80px;
      position: relative;
      .food-name {
        float: left;
      }
      .food-price {
        float: right;
      }
      .food-count {
        position: absolute;
        left: 10px;
        bottom: 10px;
      }
    }
  }
  .footer {
    position: fixed;
    width: 300px;
    height: 50px;
    bottom: 20px;
    // 经典left:50+translateX:-50%达到水平居中
    left: 50%;
    transform: translateX(-50%);
    border-radius: 25px;
    background-color: black;
    opacity: 0.9;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    overflow: hidden;
    .total-price{
      padding-left: 40px;
    }
    .submit-btn{
      padding: 20px;
      background-color: orange;
      height: 100%;
      line-height: 50px;
      cursor: pointer;
    }
  }
}
</style>